<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt"  uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title><spring:message code="head.clothGarment"></spring:message>-<spring:message code="login"></spring:message></title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/NormalizeFile.css">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/public.css">
    <!--登录注册忘记密码三个页面的样式-->
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/web/css/subpage/login.css">
</head>
<body class="loginbody">
<div class="contenter mt134">
    <a href="${pageContext.request.contextPath }/web/main/index" onfocus="blur()">
    	<img class="loginlogo" src="${pageContext.request.contextPath }/web/img/logo.png">
    </a>
<h2 class="logintitle"><spring:message code="login"></spring:message></h2>
    <!--中间内容部分begin-->
    <div class="logincase">
         <form id="signupForm" action="javascript:void(0)">
         	<input type="hidden" name="language" value="1">
         	<input type="hidden" name="redirectUrl" value="${redirectUrl }"/>
             <div>
                 <input id="telphone" name="telphone" class="form-control" placeholder="<spring:message code="login.phone"></spring:message>" type="text" aria-required="true" aria-invalid="true" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" maxlength="11" minlength="11">
             </div>
             <div>
                 <input id="password" name="password" class="form-control" placeholder="<spring:message code="login.loginPassword"></spring:message>" type="password">
             </div>
             <div class="remember-password">
                 <input type="checkbox" onclick="check();" id="rmbPassword"><spring:message code="remember"></spring:message>
             </div>
             <button type="submit" class="submit" onclick="logsubmit();"><spring:message code="login"></spring:message></button>
             <div class="footer-case-bottom">
             	<label class="reg-now"><spring:message code="loginMessage"></spring:message>
             		<a href="${pageContext.request.contextPath }/web/member/register"><spring:message code="login.register"></spring:message></a>
           		</label>
           			<a href="${pageContext.request.contextPath }/web/member/forgetPassword" class="forget-password"><spring:message code="login.forgotPassword"></spring:message></a>
       			<div class="clearfix">
       			</div>
   			</div>
        </form>
    </div>
    <!--中间内容部分end-->
</div>
<!--全局-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/h-ui/lib/layer/2.1/layer.js"></script>
<jsp:include page="../main/bottom.jsp"></jsp:include>
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/public.js"></script>
<!--ie789下placeholder不兼容-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/placeholder.js"></script>
<!-- jQuery Validation plugin javascript   表单验证-->
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/plugins/validate/jquery.validate.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/web/js/plugins/validate/messages_zh.min.js"></script>
<!--登录注册忘记密码三个页面的js-->
<%-- <script type="text/javascript" src="${pageContext.request.contextPath }/web/js/subpage/login.js"></script> --%>
<script type="text/javascript">
$(function(){
	getRememberInfo();
	
	var icon = "*";
    //以下为登录页面
    $("#signupForm").validate({
        rules: {
            telphone:{
                required: true,
                number:true,
                minlength:11,
                maxlength: 11,
                isMobile : true
            },
            password: {
                required: true,
                minlength: 6,
                maxlength: 15,
            }
        },
        messages: {
            telphone:{
                required: icon + '<spring:message code="forgotPassword.enterPhone"></spring:message>',
                number:icon +'<spring:message code="forgotPassword.validNumber"></spring:message>',
                minlength:icon +'<spring:message code="forgotPassword.enter11Digits"></spring:message>',
                maxlength:icon +'<spring:message code="forgotPassword.enter11Digits"></spring:message>',
                isMobile:icon +'<spring:message code="forgotPassword.phoneFormatError"></spring:message>'
            },
            password: {
                required: icon + '<spring:message code="forgotPassword.enterPassword"></spring:message>',
                minlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>',
                maxlength: icon + '<spring:message code="forgotPassword.password6To15"></spring:message>'
            }
        }
    });
 	// 手机号码验证
	jQuery.validator.addMethod("isMobile", function(value, element) {
		var length = value.length;
		var mobile = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
		return this.optional(element) || (length == 11 && mobile.test(value));
	}, "请正确填写您的手机号码");
})
function logsubmit(){
	var phone=$("#telphone").val();
	var passWord=$("#password").val();
	if(phone ==""){
		layer.msg('<spring:message code="login.phoneCannotEmpty"></spring:message>',{icon:0,time:1000});
		$("#telphone").focus();
		return false;
	}else{
		 var reg = /^1[3|4|5|7|8][0-9]\d{4,8}$/;
		 if (phone.length!=11||!(reg.test(phone))) {
			layer.msg('<spring:message code="login.numberFormatError"></spring:message>',{icon:0,time:1000});
			$("#telphone").focus();
			return false; 
		 }
	}
	if(passWord==""){
		layer.msg('<spring:message code="login.passwordCannotEmpty"></spring:message>',{icon:0,time:1000});
		$("#password").focus();
		return false;
	}
	if(document.all.rmbPassword.checked){
		setCookie("userName",phone,24,"/");
		setCookie("userPassword",passWord,24,"/");	
		setCookie("state",1,24,"/");
		}else{
			deleteCookie("userName","/");
			deleteCookie("userPassword","/");
			deleteCookie("state","/");
		}
	var index1 = layer.load(1, {
		  shade: [0.4,'#999999']
	})
	$.ajax({
	    url: '${pageContext.request.contextPath}/web/logIn/landing',
	    type:'POST',
	    data:$("#signupForm").serialize(),
	    success: function(result){
	    layer.close(index1);
	       if(result == 1){
    		   layer.msg('<spring:message code="login.loginSuccess"></spring:message>',{icon:1,time:1000});
    		   var url=$('input[name="redirectUrl"]').val();
 	    	  if(url!=null&&url!=""){
 	    		  location.href=url;
 	    	  }else{
 	    		 window.setTimeout("window.location.href='${pageContext.request.contextPath}/web/main/index'",2000);
 	    	  }
	       }else if(result == -2){
	    	   layer.msg('<spring:message code="login.memberstop"></spring:message>',{icon:0,time:1000});
	       }else if(result == -1){
	    	   layer.msg('<spring:message code="login.numberFormatError"></spring:message>',{icon:0,time:1000});
	       }else if(result == 0){
	    	   layer.msg('<spring:message code="login.errorPassword"></spring:message>',{icon:0,time:1000});
	       }else if(result == 2){
	    	   layer.msg('<spring:message code="login.noexist"></spring:message>',{icon:0,time:1000});
	       }else if(result == 3){
	    	   layer.msg('<spring:message code="login.stop"></spring:message>',{icon:0,time:1000});
	       }else{
	    	   layer.msg('<spring:message code="login.fail"></spring:message>',{icon:0,time:1000});
	       } 
    	}
	});
}

function check() {
	var checked = document.getElementById("rmbPassword")
	if (checked.checked == true) {
		setCookie("state", 1, 24, "/");
	} else {
		setCookie("state", 2, 24, "/");
	}
}

//获取cookie信息
function getRememberInfo() {
	try {
		var userName = "";
		var userPassword = "";
		var state = "";
		userName = getCookieValue("userName");
		userPassword = getCookieValue("userPassword");
		state = getCookieValue("state");
		document.getElementById("telphone").value = userName;
		document.getElementById("password").value = userPassword;
		if (state == 1 && state == "1") {
			$("#rmbPassword").prop("checked", "true");
		}
	} catch (err) {
		layer.msg("NO RMB PASSWORD!",{icon:0,time:1000});
	}
}

//新建cookie。
//hours为空字符串时,cookie的生存期至浏览器会话结束。hours为数字0时,建立的是一个失效的cookie,这个cookie会覆盖已经建立过的同名、同path的cookie（如果这个cookie存在）。
function setCookie(name, value, hours, path) {
	var name = escape(name);
	var value = escape(value);
	var expires = new Date();
	expires.setTime(expires.getTime() + hours * 3600000);
	path = path == "" ? "" : ";path=" + path;
	_expires = (typeof hours) == "string" ? "" : ";expires="
			+ expires.toUTCString();
	document.cookie = name + "=" + value + _expires + path;
}
//获取cookie值
function getCookieValue(name) {
	var name = escape(name);
	//读cookie属性，这将返回文档的所有cookie
	var allcookies = document.cookie;
	//查找名为name的cookie的开始位置
	name += "=";
	var pos = allcookies.indexOf(name);
	//如果找到了具有该名字的cookie，那么提取并使用它的值
	if (pos != -1) { //如果pos值为-1则说明搜索"version="失败
		var start = pos + name.length; //cookie值开始的位置
		var end = allcookies.indexOf(";", start); //从cookie值开始的位置起搜索第一个";"的位置,即cookie值结尾的位置
		if (end == -1)
			end = allcookies.length; //如果end值为-1说明cookie列表里只有一个cookie
		var value = allcookies.substring(start, end); //提取cookie的值
		return unescape(value); //对它解码
	} else
		return ""; //搜索失败，返回空字符串
}

//删除cookie
function deleteCookie(name, path) {
	var name = escape(name);
	var expires = new Date(0);
	path = path == "" ? "" : ";path=" + path;
	document.cookie = name + "=" + ";expires="
			+ expires.toUTCString() + path;
}
</script>
</body>
</html>